package com.kavadani.profiles;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import android.content.Intent;
import android.os.Bundle;
import android.util.Base64;
import android.widget.TextView;

public class ProfileActivity extends RemoteServiceClientActivity {
	public static String _PROFILE_ACTIVITY_PACKAGE_NAME = "com.kavadani.profiles";
	public static String _PROFILE_ACTIVITY_NAME = "com.kavadani.profiles.ProfileActivity";
				
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Intent intent = getIntent();
		setContentView(R.layout.profile_activity);
		
		TextView fullName = (TextView)findViewById(R.id.full_name);
		fullName.setText(intent.getStringExtra("full-name"));
		
		TextView username = (TextView)findViewById(R.id.username);
		username.setText(intent.getStringExtra("username"));
		
		TextView company = (TextView)findViewById(R.id.company);
		company.setText(intent.getStringExtra("company"));
		
		TextView imageType = (TextView)findViewById(R.id.image_type);
		imageType.setText(intent.getStringExtra("image-type"));
		
		String imageDataString = intent.getStringExtra("image");
		
        try {          
            // Converting a Base64 String into Image byte array
            byte[] imageByteArray = Base64.decode(imageDataString, Base64.DEFAULT);
             
            // Write a image byte array into file system
            File file = new File(getFilesDir().getPath().toString()+ "/fileName.jpg");
            FileOutputStream imageOutFile = new FileOutputStream(file);
            imageOutFile.write(imageByteArray);
            
            imageOutFile.close();
 
            System.out.println("Image Successfully Manipulated!");
        } catch (FileNotFoundException e) {
            System.out.println("Image not found" + e);
        } catch (IOException ioe) {
            System.out.println("Exception while reading the Image " + ioe);
        }
		
	}

}
